import type { TableColumn, FormField } from '@/components'
import { ref } from 'vue'
import { newDeptTreeInfoAll } from '@/api/systemSetting/personnel'
import { competentDeptInfo } from "@/api/spotCheck/spotCheck";

competentDeptInfo().then((res) => {
  fields.value.forEach((i) => {
    if (i.key === 'competentDeptId') {
      i.attrs.data = res.data
    }
  })
})

export const fields = ref([
  {
    key: 'riskName',
    label: '预警名称',
    tag: 'ElInput'
  },
  {
    key: 'source',
    label: '事件类型',
    tag: 'MSelect',
    attrs: {
      options: [
        {
          label: '数据比对',
          value: 1
        },
        {
          label: '年度检查',
          value: 2
        },
        {
          label: '抽查检查',
          value: 3
        },
        {
          label: '审计巡视巡查',
          value: 4
        },
        {
          label: '网络舆情',
          value: 5
        },
        {
          label: '其他',
          value: 6
        }
      ]
    }
  },
  {
    key: 'riskType',
    label: '风险类别',
    tag: 'MSelect',
    attrs: {
      options: []
    }
  },
  {
    key: 'createTime',
    label: '创建时间',
    tag: 'el-date-picker',
    attrs: {
      format: 'YYYY-MM-DD',
      dateFormat: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      placeholder: '请选择'
    }
  },
  {
    key: 'sendState',
    label: '状态',
    tag: 'MSelect',
    attrs: {
      options: [
        {
          label: '未推送',
          value: 0
        },
        {
          label: '已推送',
          value: 1
        }
      ]
    }
  },
  {
    key: 'riskLevel',
    label: '风险等级',
    tag: 'MSelect',
    attrs: {
      options: [
        {
          label: '一级',
          value: '一级'
        },
        {
          label: '二级',
          value: '二级'
        },
        {
          label: '三级',
          value: '三级'
        }
      ]
    }
  },
  {
    key: 'competentDeptId',
    label: '主管部门',
    tag: 'el-tree-select',
    placeholder: '请选择',
    attrs: {
      style: 'width: 210px',
      data: [],
      props: {
        label: 'deptName',
        value: 'deptId',
        children: 'children'
      },
      clearable: true,
      checkStrictly: true,
      filterable: true
    }
  }
])

export const columns: TableColumn[] = [
  {
    key: 'source',
    label: '来源',
    customRender: (v) => {
      let name = ''
      try {
        name = [
          '数据比对',
          '年度检查',
          '抽查检查',
          '审计巡视巡查',
          '网络舆情',
          '其他'
        ][v - 1]
      } catch (e) {}
      return name
    }
  },
  {
    key: 'riskName',
    label: '风险对象名称'
  },
  {
    key: 'riskDetail',
    label: '事件类型'
  },
  {
    key: 'riskType',
    label: '风险类型'
  },
  {
    key: '风险级别',
    label: '风险级别',
    slot: true
  },
  {
    key: 'createTime',
    label: '创建时间'
  },
  {
    key: '状态',
    label: '状态',
    slot: true
  },
  {
    key: 'actions',
    label: '操作',
    slot: true,
    fixed: 'right',
    width: 100
  }
]

export const dialogFields: FormField[] = [
  {
    key: 'typeId',
    label: '限制时间',
    tag: 'el-date-picker',
    attrs: {
      type: 'datetimerange',
      startPlaceholder: '开始时间',
      endPlaceholder: '结束时间',
      format: 'YYYY-MM-DD HH:mm:ss',
      dateFormat: 'YYYY/MM/DD ddd',
      timeFormat: 'A hh:mm:ss'
    },
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'labelName',
    label: '账户名称',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'labelRule',
    label: '使用人',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    key: 'labelPattern',
    label: '删除阈值',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  }
]
